<?php

namespace App\Http\Requests;

use App\Http\Requests\BaseFormRequest;

class AreaRequest extends BaseFormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }


    public function scenes()
    {
        return [
            'store'=>[
				'AreaName' => 'required|max:60',
				// 'Co_ID' => 'required',
			],
			'update'=>[
				'AreaName' => 'required|max:60',
				// 'Co_ID' => 'required'
			]
        ];
    }
	
	public function messages()
    {
        return [
			'AreaName.required' => '区域名称必须',
			'AreaName.max' => '区域名称不能超过60个字符',
			'AreaName.unique' => '区域名称已添加',
			'Co_ID.required' => '所属公司必须',
        ];
    }
	
	public function withValidator($validator)
	{
		$validator->sometimes('Co_ID', 'required', function ($input) {
			return true;
		}); 
		
		$validator->sometimes('is_default', 'unique:sy_area,is_default,'.$this->input('AreaId').',AreaId,Co_ID,' . $this->input('Co_ID'), function($input){
            return $input->is_default;
        });
	}

}
